from graphviz import Digraph

# 创建有向图对象
dot = Digraph(comment='成绩判断流程图')
dot.attr('node', fontname='Microsoft YaHei')
dot.graph_attr['fontname'] = 'Microsoft YaHei'
dot.node_attr['fontname'] = 'Microsoft YaHei'
dot.edge_attr['fontname'] = 'Microsoft YaHei'
# 设置编码为UTF - 8
dot.attr('graph', encoding='UTF-8')
# 定义节点
dot.node('input', '输入成绩')
dot.node('judge', '成绩 >= 60?')
dot.node('pass', '及格')
dot.node('fail', '不及格')

# 定义边（流程走向）
dot.edge('input', 'judge')
dot.edge('judge', 'pass', label='是')
dot.edge('judge', 'fail', label='否')

# 渲染生成图形，保存为文件（这里保存为png格式，可按需调整）
dot.render('grade_judgment_flowchart', format='png', cleanup=True)